package com.xt.back.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xt.back.constant.ResultDTO;
import com.xt.back.dto.CourseMappingDto;
import com.xt.back.dto.RelationMappingDto;
import com.xt.back.entity.CourseMapping;
import com.xt.back.entity.RelationMapping;
import com.xt.back.service.IRelationMappingService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 用户关系关联表 前端控制器
 * </p>
 *
 * @author leotong
 * @since 2022-04-03
 */
@CrossOrigin
@RestController
@RequestMapping("/back/relationMapping")
@AllArgsConstructor
public class RelationMappingController {

    private IRelationMappingService relationMappingService;

    @PostMapping("/add")
    public ResultDTO<Boolean> addRelationMapping(@RequestBody RelationMapping relationMapping){
        return ResultDTO.success(relationMappingService.save(relationMapping));
    }

    @GetMapping("/remove")
    public ResultDTO<Boolean> deleteRelationMapping(int id){
        return ResultDTO.success(relationMappingService.removeById(id));
    }

    @PostMapping("/update")
    public ResultDTO<Boolean> updateCourseMapping(@RequestBody RelationMapping relationMapping){
        return ResultDTO.success(relationMappingService.updateById(relationMapping));
    }

    @PostMapping("/getRelationMapping")
    public ResultDTO<Page<RelationMappingDto>> getRelationMappingByPage(@RequestBody RelationMapping relationMapping){
        return ResultDTO.success(relationMappingService.getRelationMappingByPage(relationMapping));
    }

    @GetMapping("/getAllRelationMapping")
    public ResultDTO<List<RelationMappingDto>> getAllRelationMapping() {
        return ResultDTO.success(relationMappingService.getAllRelationMapping());
    }
}
